package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.course.CourseStore;
import com.hualan.sfzy.service.course.CourseStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CourseStoreController {
    @Autowired
    private CourseStoreService courseStoreService;
    @PostMapping("/courseStore")
    public String add(@RequestBody CourseStore courseStore) {
        return courseStoreService.add(courseStore) >0 ?"success" : "fail";
    }
    @DeleteMapping("/courseStore/{id}")
    public String remove(@PathVariable int id) {
        return courseStoreService.remove(id) >0 ?"success" : "fail";
    }
    @DeleteMapping("/courseStore")
    public String removeBatch(Integer[] ids) {
        return courseStoreService.removeBatch(ids) > 0 ?"success" : "fail";
    }
    @PutMapping("/courseStore")
    public String edit(@RequestBody CourseStore courseStore) {
        return courseStoreService.edit(courseStore) >0 ?"success" : "fail";
    }
    @GetMapping("/courseStore")
    public List<CourseStore> find() {
        return courseStoreService.find();
    }
    @GetMapping("/courseStore/{id}")
    public CourseStore findById(@PathVariable int id) {
        return courseStoreService.findById(id);
    }
    @GetMapping("/courseStore/page")
    public Object findPage(
            @RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5",required = false)
            Integer pageSize
            ,CourseStore courseStore) {
        return courseStoreService.findPage(pageNum, pageSize, courseStore);
    }

}
